﻿/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2013-10-21
 * Time: 8:53
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.IO;
using System.Collections.Generic;

namespace suiji
{
	/// <summary>
	/// Description of myFunction.
	/// </summary>
	public class myFunction
	{
		public myFunction()
		{
		}
		
		public void Run()
		{

            List<String> strList = new List<String>();


            int Seed = System.DateTime.Now.Millisecond;
            int nGeShu = 10000;
            for (int i = 0; i < nGeShu; i++) 
			{
                int mySeed = i + Seed;

                String each = GetItem(1, 7, 1, 200, mySeed);

                strList.Add(each);

                //Console.WriteLine(each);
			}
			

            // 写文件.
            WriteFile("1.txt", strList);
			
			Console.WriteLine("here");
			
		}
		
		// suiji geshu  zuixiaozhi
		
		public String GetItem(int geshuMin,
		                      int geshuMax,
		                      int priceMin,
		                      int priceMax,
                              int Seed)
		{
			String strRtn = string.Empty;
			 
			// Get Dafe(1~7) 
            String strPart1 = GetRandomN(geshuMin, geshuMax, Seed);
			
			// Get 100 (1~200)
			int nPart2 = GetRandom(priceMin, priceMax, Seed);
			String strPart2 = nPart2.ToString();
			
			// Add two to one
			strRtn = strPart1 + " " + strPart2;
		
			
			return strRtn;
		}
		
		public String GetRandomN(int nMin, int nMax, int Seed)
		{
			String strRtn = string.Empty;
			
			// get random num as Geshu
            int nNum = GetRandom(nMin, nMax, Seed);
			
			// call function GetRandomString
			strRtn = GetRandomString(nNum, Seed);
			
			return strRtn;
		}
		
		// GuDing.
		// GeShu = 4;
		public String GetRandomString(int GeShu, int Seed)
		{
			String strRtn = string.Empty;
			for (int i = 0; i < GeShu; i++) 
			{
				//seed = DateTime + i * 100;

                int mySeed = Seed + i;

                int nEach = GetRandom(1, 26, mySeed);
				String each = ChangeToString(nEach);
				
				strRtn = strRtn + each;
			}
			
			return strRtn;
		}
		
		// Change from int to "String".
		public String ChangeToString(int num)
		{
			String strRtn = string.Empty;
			
			switch(num)
			{
				case 1: strRtn = "a"; break;
				case 2: strRtn = "b"; break;
				case 3: strRtn = "c"; break;
				case 4: strRtn = "d"; break;
				case 5: strRtn = "e"; break;
				case 6: strRtn = "f"; break;
				case 7: strRtn = "g"; break;
				case 8: strRtn = "h"; break;
				case 9: strRtn = "i"; break;
				case 10: strRtn = "j"; break;
				case 11: strRtn = "k"; break;
				case 12: strRtn = "l"; break;
				case 13: strRtn = "m"; break;
				case 14: strRtn = "n"; break;
				case 15: strRtn = "o"; break;
				case 16: strRtn = "p"; break;
				case 17: strRtn = "q"; break;
				case 18: strRtn = "r"; break;
				case 19: strRtn = "s"; break;
				case 20: strRtn = "t"; break;
				case 21: strRtn = "u"; break;
				case 22: strRtn = "v"; break;
				case 23: strRtn = "w"; break;
				case 24: strRtn = "x"; break;
				case 25: strRtn = "y"; break;
				case 26: strRtn = "z"; break;
			}
			
			return strRtn;
		}
		
        /// <summary>
        /// 返回介于最小值和最大值之间的值.
        /// </summary>
        /// <param name="Min"></param>
        /// <param name="Max"></param>
        /// <param name="Seed"></param>
        /// <returns></returns>
		public int GetRandom(   int Min, 
                                int Max,
                                int Seed)
		{
            Random r = new Random(Seed);
			
			int rtn = r.Next(Min, Max);
			
			return rtn;
		}


        // 写文件
        /// <summary>
        /// 把List容器写入文件
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <param name="strList">容器名字</param>
        private static void WriteFile(  string path, 
                                        List<String> strList)
        {
            FileStream fs = new FileStream(path, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);


            int nNum = strList.Count;
            for (int i = 0; i < nNum; i++)
            {
                String each = strList[i];

                sw.WriteLine(each);
            }

            sw.Flush();

            sw.Close();
            fs.Close();
        }
}
}